package com.lanyou.cook.common;

import java.io.IOException;
import java.text.ParseException;
import java.util.Date;

import org.apache.commons.lang3.time.DateParser;
import org.apache.commons.lang3.time.FastDateFormat;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;

public class DefaultDateJsonDeserializer extends JsonDeserializer<Date> {

	private static final DateParser dateParser = FastDateFormat.getInstance(Constants.DATETIME_PATTERN_1);

	@Override
	public Date deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException {
		try {
			return dateParser.parse(jp.getText());
		} catch (ParseException e) {
			return null;
		}
	}

}
